package com.itboye.ihomebank.base;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.app.ActivityManager;
import android.app.AlertDialog;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.content.res.Resources;
import android.graphics.Color;
import android.os.Build;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.util.Log;
import android.view.KeyEvent;
import android.view.MotionEvent;
import android.view.VelocityTracker;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.view.Window;
import android.view.WindowManager;
import android.widget.LinearLayout;
import android.widget.Toast;

import com.itboye.ihomebank.KeyFragment;
import com.itboye.ihomebank.R;
import com.itboye.ihomebank.activity.hetong.ActivityHuaBan;
import com.itboye.ihomebank.activity.home.ActivityXuanZuKe;
import com.itboye.ihomebank.activity.keytwo.KeyGuanLiActivity;
import com.itboye.ihomebank.activity.keytwo.KeyPuTongActivity;
import com.itboye.ihomebank.activity.keytwo.KeyZuHuActivity;
import com.itboye.ihomebank.activity.login.LoginActivity;
import com.itboye.ihomebank.activity.me.ActivityMyData;
import com.itboye.ihomebank.activity.me.ActivitySetting;
import com.itboye.ihomebank.activity.qianyue.ActivityMySign;
import com.itboye.ihomebank.activity.qianyue.OrderDetailActivity;
import com.itboye.ihomebank.bean.NotificationBean;
import com.itboye.ihomebank.bean.RedDotBean;
import com.itboye.ihomebank.bean.ResultEntity;
import com.itboye.ihomebank.bean.SIDBean;
import com.itboye.ihomebank.constants.NetPublicConstant;
import com.itboye.ihomebank.constants.SPContants;
import com.itboye.ihomebank.db.DBOpenHelper;
import com.itboye.ihomebank.db.RecordDBManager;
import com.itboye.ihomebank.interfaces.IRefreshAfterAlert;
import com.itboye.ihomebank.presenter.HousePresenter;
import com.itboye.ihomebank.presenter.UserPresenter;
import com.itboye.ihomebank.ttKey.DbService;
import com.itboye.ihomebank.util.ByAlert;
import com.itboye.ihomebank.util.DensityUtil;
import com.itboye.ihomebank.util.ListDialog;
import com.itboye.ihomebank.util.LoadingDialog;
import com.itboye.ihomebank.util.SPUtils;
import com.itboye.ihomebank.util.SaveKeyBean;
import com.itboye.ihomebank.util.UIAlertView;
import com.itboye.ihomebank.util.broad.BroadEnum;
import com.itboye.ihomebank.util.broad.RxDialogOne;
import com.itboye.ihomebank.util.controller.LoginController;
import com.itboye.ihomebank.util.controller.UnLoginState;
import com.itboye.ihomebank.util.dialog.RxDialogSureCancel;
import com.itboye.ihomebank.web.WebActivity;
import com.nostra13.universalimageloader.utils.L;
import com.ttlock.bl.sdk.constant.Constant;
import com.umeng.analytics.MobclickAgent;
import com.umeng.message.PushAgent;
import com.umeng.message.UTrack;

import java.io.Serializable;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.text.ParseException;
import java.util.List;
import java.util.Observable;
import java.util.Observer;

@SuppressLint("ResourceAsColor")
public abstract class BaseOtherActivity extends FragmentActivity implements
        OnClickListener, Observer {
    protected Context mContext;
    private View statusBar;
    public boolean isGestureOpen;
    private ViewContainer container;
    LoadingDialog progressDialog = null;
    UserPresenter userPresenter;
    HousePresenter mHousePresenter;
    RecordDBManager dbManager;
    DBOpenHelper dbOpenHelper;
    RxDialogOne dialogOne;
    String username;
    String password;
    IRefreshAfterAlert ref;
    public String getAppVersionName(Context context) {
        String versionName = "";
        try {
            // ---get the package info---
            PackageManager pm = context.getPackageManager();
            PackageInfo pi = pm.getPackageInfo(context.getPackageName(), 0);
            versionName = pi.versionName;

            if (versionName == null || versionName.length() <= 0) {
                return "";
            }
        } catch (Exception e) {
            Log.e("VersionInfo", "Exception", e);
        }
        return versionName;
    }
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);
        //判断是否有底部导航栏
//        if (checkDeviceHasNavigationBar(this)){
//            getWindow().getDecorView().setPadding(0,0,0,getNavigationBarHeight(this));
//        }
        getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN);
        setContentView(layout_id());
        username=SPUtils.get(this, null, SPContants.MOBILE, "") + "";
        password=SPUtils.get(this, null, SPContants.MOBILE_PASS, "") + "";
        mContext = getApplicationContext();
        progressDialog = new LoadingDialog();
        PushAgent.getInstance(getApplicationContext()).onAppStart();
        userPresenter = new UserPresenter(this);
        mHousePresenter =new HousePresenter(this);
        other();
        onReadIntent(savedInstanceState);
        onInitController();
        onInit();
        dbOpenHelper = new DBOpenHelper(BaseOtherActivity.this);
        PushAgent.getInstance(MyApplcation.ctx).onAppStart();

        //收到友盟推送弹出相应的弹框(就这个APP用到了。。。。。。)
        IntentFilter intentFilter=new IntentFilter(BroadEnum.TanKuangType);
        registerReceiver(broadcastReceiver,intentFilter);

    }

    //收到友盟推送弹出相应的弹框(就这个APP用到了。。。。。。)
    BroadcastReceiver broadcastReceiver=new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {

            String title="";//标题
            String content="";//内容
            String tv_lift="";//左边按键名称
            String tv_right="";//右边按键名称

            final String type=intent.getStringExtra("type");
            final String contract_no=intent.getStringExtra("contract_no");
            String text = intent.getStringExtra("content");
            if (type.equals(BroadEnum.ZuKeShenQing)){//3租客申请签约，经纪人选择租客弹框
                title="选择租客";
                tv_lift="取消";
                tv_right="选择租客";
                content=text;
            }else  if (type.equals(BroadEnum.JingJiRenTianXie)){//经纪人填好合同，租客打开APP弹出，去签订合同
                title="签约消息";
                tv_lift="查看合同";
                tv_right="去签约";
                content=text;
            }else  if (type.equals(BroadEnum.FuJianDan)){//经纪人填写好附件单后，租客弹出确认
                title="设施清单确认";
                tv_lift="确认";
                tv_right="有异议";
                content=text;
            }else  if (type.equals(BroadEnum.ZhiFuZuJin)){ //租客到期支付租金
                title="支付房租";
                tv_lift="取消";
                tv_right="去支付";
                content=text;
            }else if (type.equals(BroadEnum.newDevice)){//新设备登陆
                title ="新设备登录";
                tv_lift ="去登录";
                tv_right = "取消";
                content = text;
            }


                dialogOne= new RxDialogOne(BaseOtherActivity.this,title,content,tv_lift,tv_right);//提示弹窗
                dialogOne.setOnKeyListener(new DialogInterface.OnKeyListener() {
                    @Override
                    public boolean onKey(DialogInterface dialog, int keyCode, KeyEvent event) {
                        if (keyCode == KeyEvent.KEYCODE_BACK) {
                            //do something...
                            if (type.equals(BroadEnum.newDevice)){
                                Log.d("==========one","done");
                                exit();
                                return false;
                            }

                        }
                        return true;
                    }
                });
                if (type.equals(BroadEnum.newDevice)){
                    dialogOne.getCancelView().setVisibility(View.GONE);
                    dialogOne.getQuXiaoView().setVisibility(View.GONE);

                }

                dialogOne.getSureView().setOnClickListener(new View.OnClickListener() {//左按建
                    @Override
                    public void onClick(View v) {
                        dialogOne.cancel();
                        Intent intent=null;
                        if (type.equals(BroadEnum.ZuKeShenQing)){//租客申请签约，经纪人选择租客弹框（取消）

                        }else  if (type.equals(BroadEnum.JingJiRenTianXie)){//经纪人填好合同，租客打开APP弹出，去签订合同(查看合同)
                            intent = new Intent(BaseOtherActivity.this, WebActivity.class);
                            intent.putExtra("url", NetPublicConstant.HETONG_URL
                                    + "?uid=" + (SPUtils.get(BaseOtherActivity.this, null,SPContants.USER_ID, "") + "")
                                    + "&psw=" + SPUtils.get(BaseOtherActivity.this, null, SPContants.PASSWORD, "") + ""
                                    + "&contract_no=" + contract_no + "&pc=1");
                            intent.putExtra("title", "查看合同");
                            startActivity(intent);
                        }else  if (type.equals(BroadEnum.FuJianDan)){//经纪人填写好附件单后，租客弹出确认(确认附件单)
                            userPresenter.querenZichan((SPUtils.get(BaseOtherActivity.this, null,SPContants.USER_ID, "") + ""),
                                    contract_no,"0");
                            v.setBackgroundColor(getResources().getColor(R.color.gray_divider));
                        }else  if (type.equals(BroadEnum.ZhiFuZuJin)){ //租客到期支付租金（取消）

                        }else if (type.equals(BroadEnum.newDevice)){//新设备登录 （去登录）
                            exit();
                            intent = new Intent(BaseOtherActivity.this,LoginActivity.class);
                            startActivity(intent);
                        }
                    }
                });
                dialogOne.getCancelView().setOnClickListener(new View.OnClickListener() {//右按键
                    @Override
                    public void onClick(View v) {
                        dialogOne.cancel();
                        Intent intent=null;
                        if (type.equals(BroadEnum.ZuKeShenQing)){//租客申请签约，经纪人选择租客弹框
                            intent = new Intent(BaseOtherActivity.this,ActivityXuanZuKe.class);
                            startActivity(intent);
                        }else  if (type.equals(BroadEnum.JingJiRenTianXie)){//经纪人填好合同，租客打开APP弹出，去签订合同（去签约）
                            intent = new Intent(BaseOtherActivity.this, ActivityMySign.class);//跳转到哪里 待确认
                            startActivity(intent);
                        }else  if (type.equals(BroadEnum.FuJianDan)){//经纪人填写好附件单后，租客弹出确认（有异议）
                            ByAlert.alert("有异议");//功能待确认
                            userPresenter.querenZichan((SPUtils.get(BaseOtherActivity.this, null,SPContants.USER_ID, "") + ""),
                                    contract_no,"1");
                        }else  if (type.equals(BroadEnum.ZhiFuZuJin)){ //租客到期支付租金(去支付房租)
                            intent = new Intent(BaseOtherActivity.this,OrderDetailActivity.class);
                            intent.putExtra("contractNo", contract_no);//少个合同号
                            startActivity(intent);
                        }else if (type.equals(BroadEnum.newDevice)){

                        }
                    }
                });
                dialogOne.getQuXiaoView().setOnClickListener(new OnClickListener() {//取消按键
                    @Override
                    public void onClick(View v) {
                        dialogOne.cancel();
                    }
                });
                dialogOne.show();
//            if (MyApplcation.dialogOne!=null
//                    &&MyApplcation.dialogOne.getTitleView().getText().toString().trim().equals(title)){//防止多次弹出
//
//            }else {

//            }

        }
    };

    //判断是否存在NavigationBar
    public  boolean checkDeviceHasNavigationBar(Context context) {
        boolean hasNavigationBar = false;
        Resources rs = context.getResources();
        int id = rs.getIdentifier("config_showNavigationBar", "bool", "android");
        if (id > 0) {
            hasNavigationBar = rs.getBoolean(id);
        }
        try {
            Class systemPropertiesClass = Class.forName("android.os.SystemProperties");
            Method m = systemPropertiesClass.getMethod("get", String.class);
            String navBarOverride = (String) m.invoke(systemPropertiesClass, "qemu.hw.mainkeys");
            if ("1".equals(navBarOverride)) {
                hasNavigationBar = false;
            } else if ("0".equals(navBarOverride)) {
                hasNavigationBar = true;
            }
        } catch (Exception e) {

        }
        return hasNavigationBar;

    }

   UIAlertView uiAlertView;
    //加载弹框 切换锁服务器
    public void showAlert(){
//        String o = (String) SPUtils.get(MyApplcation.ctx, null, SPContants.LOCK_SESSION, "");
//        if ("".equals(o)){
        if (uiAlertView==null){
            uiAlertView= new UIAlertView(this, "温馨提示","服务器出小差了,重新尝试连接", "确定", "取消");

        }
            uiAlertView.show();
            uiAlertView.setClicklistener(new UIAlertView.ClickListenerInterface() {
                @Override
                public void doLeft() {
                    //获取sid 替换uid
                    userPresenter.getSid(username,password);
                    uiAlertView.dismiss();
                    uiAlertView=null;
                }

                @Override
                public void doRight() {
                    uiAlertView.dismiss();
                    uiAlertView=null;
                }
            });
//        }

    }

    @Override
    public void update(Observable observable, Object data) {
        // TODO Auto-generated method stub
        ResultEntity entity = handlerError(data);
//        ByAlert.alert(entity.getMsg());
        if (entity != null) {
            if (entity.getEventType() == UserPresenter.qingdan_success) {//租客确认附件单
                ByAlert.alert(entity.getData());
                sendBroadcast(new Intent("showRedDot"));
            } else  if (entity.getEventType() == UserPresenter.qingdan_fail){
                ByAlert.alert(entity.getData());
            } else if (entity.getEventType()==UserPresenter.By_GETSID_success){//获取sid 成功
                SIDBean data1 = (SIDBean) entity.getData();
                SPUtils.put(MyApplcation.ctx,null, SPContants.LOCK_SESSION,data1.getSid());
                SPUtils.put(MyApplcation.ctx,null,SPContants.ISLOCK,true);
            }else if (entity.getEventType()==UserPresenter.By_GETSID_fail){
                ByAlert.alert(entity.getMsg());
            }
        }
    }
    @Override
    protected void onDestroy() {
        super.onDestroy();
        unregisterReceiver(broadcastReceiver);
    }

    @Override
    protected void onRestart() {
        super.onRestart();

        if (dialogOne!=null){
            dialogOne.cancel();
        }
        Log.d("resume===","onRestart");
    }

    protected abstract int layout_id();

    protected abstract void onInitController();

    protected abstract void onInit();

    protected abstract void onReadIntent(Bundle bundle);


    public void other() {

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
            Window window = getWindow();
            // Translucent status bar
            window.setFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS,
                    WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);

            statusBar = new View(this);
            //设置顶部状态栏透明
//            window.setStatusBarColor(Color.TRANSPARENT);
            window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS
                    | WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
            //设置可沉浸
            window.getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN |View.SYSTEM_UI_FLAG_LAYOUT_STABLE);
//            window.getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN 顶部
//                    | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION 底部
//                    |View.SYSTEM_UI_FLAG_LAYOUT_STABLE); view 稳定 防止重新layout
            window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
            if (Build.VERSION.SDK_INT >=21){
                window.setStatusBarColor(Color.TRANSPARENT);
            }
//            window.setNavigationBarColor(Color.TRANSPARENT);

            ViewGroup.LayoutParams param = new ViewGroup.LayoutParams(
                    ViewGroup.LayoutParams.MATCH_PARENT, getStatusBarHeight());
            statusBar.setLayoutParams(param);
            setStatusBarColor(getResources().getColor(R.color.title_blue));

            container = new ViewContainer(getApplicationContext());
            container.setOrientation(LinearLayout.VERTICAL);
            container.addView(statusBar);
        }
        smartInject();// 自动获取控件
    }

    public static final String EVENT_TYPE_UNKNOWN = BaseOtherActivity.class
            .getName() + "_unknown";

    /**
     * @param data
     * @return 2016-4-23 hebidu
     */
    public ResultEntity handlerError(Object data) {
        ResultEntity result = (ResultEntity) data;
        if (result == null) {
            result = new ResultEntity("-1", "数据格式错误!~", data);
            return result;
        }

        if (result.hasError()) {
            //   ByAlert.alert(result.getMsg());
            if (result.getMsg().contains("java.net.UnknownHostException")) {
                ByAlert.alert("请连接网络 ");
            } else {
//                ByAlert.alert(result.getMsg());
            }
//            result.setEventType(EVENT_TYPE_UNKNOWN);
            return result;
        }

        return result;
    }


    @Override
    protected void onResume() {
        // TODO Auto-generated method stub
        super.onResume();
        MobclickAgent.onResume(this);
        /**
         * 在这里本来可以使用if (!isAppOnForeground()) {//to do
         * sth}，但为了避免再次调用isAppOnForeground()而造成费时且增大系统的开销，故在这里我应用了一个标志位来判断
         */
        Log.d("resume===","resume");

    }

    @Override
    protected void onPause() {
        // TODO Auto-generated method stub
        super.onPause();
        MobclickAgent.onPause(this);
        Log.d("resume===","pause");
    }

    /**
     * 设置状态栏颜色，
     * @param color 颜色资源id， 如 R.color.orange</br> 0 黑色
     */
    protected void setStatusBarColor(int color) {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
            if (color == 0) {
                statusBar.setBackgroundColor(Color.BLACK);
            } else {
                statusBar.setBackgroundColor(color);
            }

        }
    }


    /**
     * 获取底部导航栏高度
     * @return
     */
    public  int getNavigationBarHeight(Context context) {
        Resources resources = context.getResources();
        int resourceId = resources.getIdentifier("navigation_bar_height", "dimen", "android");
        //获取NavigationBar的高度
        return resources.getDimensionPixelSize(resourceId);
    }

    /**
     * 显示进度对话框,带有消息 flag 是否可以取消
     */
    @SuppressLint("NewApi")
    public void showProgressDialog(String message, boolean flag) {
        if (progressDialog == null)
            return;
        setProgressDialogMessage(message);
        if (progressDialog.isAdded()) {

        }else {
            progressDialog.show(getFragmentManager(), message);
            progressDialog.setCancelable(flag);
        }
    }

    /**
     * 设置进度对话框消息
     *
     * @param message
     */
    public void setProgressDialogMessage(String message) {
        progressDialog.setMsg(message);
    }

    /**
     * 关闭进度对话框
     */
    @SuppressLint("NewApi")
    public void closeProgressDialog() {
        if (progressDialog != null) {
//			if (progressDialog.getDialog().isShowing()) {
            progressDialog.dismiss();
//			}
        }
    }

    private void smartInject() {

        try {
            Class<? extends Activity> clz = getClass();

            while (clz != BaseOtherActivity.class) {

                Field[] fs = clz.getDeclaredFields();
                Resources res = getResources();
                String packageName = getPackageName();
                for (Field field : fs) {
                    if (!View.class.isAssignableFrom(field.getType())) {
                        continue;
                    }
                    int viewId = res.getIdentifier(field.getName(), "id",
                            packageName);
                    if (viewId == 0)
                        continue;
                    field.setAccessible(true);
                    try {
                        View v = findViewById(viewId);
                        field.set(this, v);
                        Class<?> c = field.getType();
                        Method m = c.getMethod("setOnClickListener",
                                android.view.View.OnClickListener.class);
                        m.invoke(v, this);
                    } catch (Throwable e) {
                    }
                    field.setAccessible(false);

                }

                clz = (Class<? extends Activity>) clz.getSuperclass();

            }
        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

    }

    @Override
    public void onClick(View v) {

    }

    /**
     * 屏幕左侧右划返回容器 ,
     *
     * @author Young
     */
    private class ViewContainer extends LinearLayout {

        private int leftMargin;
        private VelocityTracker tracker;
        private float startX;
        private float startY;

        public ViewContainer(Context context) {
            super(context);
            leftMargin = DensityUtil.dip2px(35);

        }

        @Override
        public boolean dispatchTouchEvent(MotionEvent ev) {
            if (isGestureOpen == false) {
                return super.dispatchTouchEvent(ev);
            }
            switch (ev.getAction()) {
                case MotionEvent.ACTION_CANCEL:
                case MotionEvent.ACTION_UP:
                    // 当满足下面条件时 视为 右划关闭手势
                    // 起始按压位置x坐标小与leftMargin&& 向右滑动 && 向右滑动距离 > 竖直方向距离
                    if (startX < leftMargin
                            && ev.getRawX() > startX
                            && ev.getRawX() - startX > Math.abs(ev.getRawY()
                            - startY)) {
                        // 速度大于2500时关闭activity
                        tracker.computeCurrentVelocity(1000);
                        if (tracker.getXVelocity() > 2500) {
                            finish();
                        }

                    }

                    tracker.recycle();
                    break;

                case MotionEvent.ACTION_DOWN:
                    startX = ev.getRawX();
                    startY = ev.getRawY();
                    tracker = VelocityTracker.obtain();
                    tracker.addMovement(ev);
                    break;
                case MotionEvent.ACTION_MOVE:
                    tracker.addMovement(ev);
                    break;
            }

            return super.dispatchTouchEvent(ev);
        }

        @Override
        public boolean onTouchEvent(MotionEvent event) {
            if (isGestureOpen == false) {
                return super.onTouchEvent(event);
            }
            return true;
        }
    }
    /**
     * 设置状态栏高度
     * @param
     */
    public void setStatusBarHeight(View view) {
        ViewGroup.LayoutParams params = view.getLayoutParams();
        params.height = getStatusBarHeight();
        view.setLayoutParams(params);
    }

    /**
     * 获取状态栏高度
     * @return
     */
    protected int getStatusBarHeight() {
        int result = 0;
        int resourceId = getResources().getIdentifier("status_bar_height",
                "dimen", "android");
        if (resourceId > 0) {
            result = getResources().getDimensionPixelSize(resourceId);
        }
        return result;
    }

    /**
     * 程序是否在前台运行
     *
     * @return
     */
    public boolean isAppOnForeground() {

        ActivityManager activityManager = (ActivityManager) getApplicationContext()
                .getSystemService(Context.ACTIVITY_SERVICE);
        String packageName = getApplicationContext().getPackageName();
        /**
         * 获取Android设备中所有正在运行的App
         */
        List<ActivityManager.RunningAppProcessInfo> appProcesses = activityManager
                .getRunningAppProcesses();
        if (appProcesses == null)
            return false;

        for (ActivityManager.RunningAppProcessInfo appProcess : appProcesses) {
            // The name of the process that this object is associated with.
            if (appProcess.processName.equals(packageName)
                    && appProcess.importance == ActivityManager.RunningAppProcessInfo.IMPORTANCE_FOREGROUND) {
                return true;
            }
        }

        return false;
    }
   //退出登录

    public void exit() {
        // SPUtils.clear(ActivitySetting.this, "share_by_data");
        LoginController.setLoginState(new UnLoginState());
        // SPUtils.clear(MyApplcation.ctx, SPUtils.DEFAULT_FILE_NAME);
        deleteInfo();
        dbOpenHelper.deleteDatabase(this);
        try {
            KeyFragment.getInstance().panduan(null);
            KeyFragment.getInstance().refresh();
            DbService.deleteAllKey();

            if (KeyFragment.keyDao != null) {
                KeyFragment.keyDao.deleteAll();
            }
            if (KeyGuanLiActivity.keyDao != null) {
                KeyGuanLiActivity.keyDao.deleteAll();
            }
            if (KeyZuHuActivity.keyDao != null) {
                KeyZuHuActivity.keyDao.deleteAll();
            }
            if (KeyPuTongActivity.keyDao != null) {
                KeyPuTongActivity.keyDao.deleteAll();
            }
        } catch (Exception e) {
            // TODO: handle exception
        }

        Intent intent1 = new Intent(ActivityMyData.AVARTACTION);// 通知MeFragment更新界面
        sendBroadcast(intent1);

    }

    private void deleteInfo() {
        dbManager = new RecordDBManager(this);
        dbManager.deleteCaoGao();
        MyApplcation.getInstance().mPushAgent.removeAlias(
                SPUtils.get(this, null, SPContants.USER_ID, "") + "", SPContants.UMENG_ALIAS,
                new UTrack.ICallBack() {

                    @Override
                    public void onMessage(boolean arg0, String arg1) {
                        // TODO Auto-generated method stub

                    }
                });
        SPUtils.put(this, null, SPContants.USER_ID, "");
        SPUtils.put(this, null, SPContants.MOBILE, "");
        SPUtils.put(this, null, SPContants.EMAIL, "");
        SPUtils.put(this, null, SPContants.NICK, "");
        SPUtils.put(this, null, SPContants.PASSWORD, "");
        SPUtils.put(this, null, SPContants.AVATAR_URL, "");
        SPUtils.put(this, null, SPContants.USERNAME, "");
        SPUtils.put(this, null, SPContants.WX_Openid, "");
        SPUtils.put(this, null, SPContants.IdentityValidate, "");
        SPUtils.put(this, null, SPContants.BrokerValidate, "");
        SPUtils.put(this, null, SPContants.IS_LOGINED, false);
        SPUtils.put(this, null, SPContants.IdNumBer, "");
        SPUtils.put(this, null, SPContants.RealName, "");
        SPUtils.put(this, null, SPContants.WalletPass, "");
        SPUtils.put(this, null, SPContants.HUANKUAN, "");
        SPUtils.put(this, null, SPContants.OPENID, "");
        SaveKeyBean.saveData("2", null);
        SaveKeyBean.saveDataTwo("2", null);
        SPUtils.put(this, null, SPContants.RECORDS, "");
        SPUtils.put(this, null, SPContants.RECORDS_LOCKID, "");

        SPUtils.put(this, null, SPContants.MESS_NEW, false);
        SPUtils.put(this, null, SPContants.BAIMA_LOCKMAC, "");
        SPUtils.put(this, null, SPContants.BAIMA_DATE, "");
        SPUtils.put(this, null, SPContants.CHANGYONG_MAC, "");
        SPUtils.put(this, null, SPContants.CHANGYONG_TYPE, "");
        SPUtils.put(this, null, SPContants.KEY_PLAY, "");
        //红点
        SPUtils.put(this,null,SPContants.YUQI_COUNT,0);//逾期合同数
        SPUtils.put(this,null,SPContants.TOTAL_MESSAGE,0);//消息总数
        SPUtils.put(this,null,SPContants.SYSTEM_MESSAGE,0);//系统消息

        SPUtils.put(this,null,SPContants.CONTRANCT_MESSAGE,0);//签约消息
        SPUtils.put(this,null,SPContants.LOCK_MESSAGE,0);//锁消息
        SPUtils.put(this,null,SPContants.REPAIR_COUNT,0);//未维修数
        SPUtils.put(this,null,SPContants.BILL_COUNT,0);//账单数
        SPUtils.put(this,null,SPContants.FUJIAN_ORDER,false);//有无未填写的附件单
    }

}
